package com.rr.learningdemo.stream.service.impl;

import com.rr.learningdemo.pojo.Person;
import com.rr.learningdemo.stream.bindings.MyProcessor;
import com.rr.learningdemo.stream.service.SendMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.cloud.stream.messaging.Processor;
import org.springframework.context.annotation.Bean;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.function.Consumer;

/**
 * @author zhuangcanrun
 * @Date 2021/06/15/17:30
 * @description
 **/

//@EnableBinding(MyProcessor.class)
@Service
public class SendMessageServiceImpl {

//    @Autowired
//    private Processor processor;
//    @Autowired
//    private MyProcessor myProcessor;

    @Autowired
    private StreamBridge streamBridge;

//    public void sendMessageByOutput(String message) {
//        System.out.println("发送消息：{" + message + "}到exchange1");
//        processor.output().send(MessageBuilder.withPayload(message)
//                .setHeader("contentType", "text/plain")
//                .setHeader("hehe", "text")
//                .build());
//    }
//    public void sendMessageByMyOutput(String message) {
//        System.out.println("发送消息：{" + message + "}到exchange2");
//        myProcessor.myOutput().send(MessageBuilder.withPayload(message)
//                .setHeader("contentType", "text/plain")
//                .build());
//    }

    public void sendByStreamBridge(String message){
        streamBridge.send("uppercase-in-0", message);
        streamBridge.send("uppercase-out-0", message);
        streamBridge.send("send-out-0", message);
        streamBridge.send("send-out-0", message);
    }

    public void sendMethod() {
        String message = UUID.randomUUID().toString();
        streamBridge.send("exchange1", message);
        System.out.println("************发送了message："+message);
    }

}
